import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { TSkill } from "../../../../../Message/Db/Tables/TSkill";
import { Cache } from "../../../cache/Cache";
import { EGuildStructureType } from "../../../../../Message/Public/EGuildStructureType";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GuildSkillItem } from "./GuildSkillItem";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Language } from "../../../../../extend/language/Language";
import { MsgManager } from "../../../manager/MsgManager";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { SPlayerGuildInfo } from "../../../../../Message/Game/SPlayerGuildInfo";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class GuildSkillPublicCellRenderer
    
    export  class GuildSkillPublicCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this._skill = arg1 as TSkill;
            this._skillItem.skillInfo = null;
            if (this._skill) 
            {
                this._upCostRes = this._skill.needGuildMoney;
                this._activateCostContri = this._skill.needGuildContribution;
                this._needSchoolLevel = this._skill.guildSchoolLevel;
                this._resource = Cache.instance.guild.myGuildInfo.money;
                this._contribution = Cache.instance.guild.myGuildInfo.contribution;
                this._schoolLevel = Cache.instance.guild.getStructureLevel(EGuildStructureType.convert(EGuildStructureType._EGuildSchool));
                this._nameTxt.htmlText = this._skill.skillName;
                this._levelTxt.htmlText = this._skill.skillLevel.toString();
                this._upCostlTxt.htmlText = this._upCostRes.toString();
                this._activateCostTxt.htmlText = this._activateCostContri.toString();
            }
            return;
        }

        /* internal  */init(): void
        {
            var loc1=85;
            var loc2=170;
            ObjCreate.createBg(0, 0, 215, 80, this, ImagesConst.DisabledBg);
            ObjCreate.createBg(10, 8, 65, 65, this, ImagesConst.PackItemBg);
            this._skillItem = new GuildSkillItem();
            this._skillItem.setSize(60, 60);
            this._skillItem.move(12, 10);
            this.addChild(this._skillItem);
            this._nameTxt = ObjCreate.createTextField("", loc1, 5, 200, 20, this, GlobalStyle.textFormat6);
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._levelTxt = ObjCreate.createTextField("1", loc2, 5, 200, 20, this, GlobalStyle.textFormatGreen);
            this._levelTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            ObjCreate.createTextField(Language.getString(57568), loc1, 20, 200, 20, this);
            this._upCostlTxt = ObjCreate.createTextField("0", loc2, 20, 200, 20, this, GlobalStyle.textFormatOrange);
            this._upCostlTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            ObjCreate.createTextField(Language.getString(57569), loc1, 40, 200, 20, this);
            this._activateCostTxt = ObjCreate.createTextField("0", loc2, 40, 200, 20, this, GlobalStyle.textFormatOrange);
            this._activateCostTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._upBtn = ObjCreate.createGButton(Language.getString(57570), loc1, 57, 50, 20, this);
            this._upBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onUpBtnClickHandler);
            this._upBtn.drawNow();
            this._activateBtn = ObjCreate.createGButton(Language.getString(57571), 145, 57, 50, 20, this);
            this._activateBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onActivateBtnClickHandler);
            this._activateBtn.drawNow();
            return;
        }

        /* internal  */onUpBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._skill) 
            {
                if (this._resource < this._upCostRes) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(57572));
                    return;
                }
                if (this._schoolLevel < this._needSchoolLevel) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(57564));
                    return;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.skillUpgradeReq, this._skill.skillId));
            }
            return;
        }

        /* internal  */onActivateBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var e: Object /* flash.events.Event */;
            var onClickHandler: Function;

            var loc1;
            e = arg1;
            if (this._skill) 
            {
                onClickHandler = (arg1: int): void
                {
                    if (arg1 == Alert.OK) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.skillLearnReq, _skill.skillId));
                    }
                    return;
                }
                if (this._skill.skillLevel < 1) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(57573));
                    return;
                }
                if (this._enableSkillNum >= this._maxEnableNum) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(57574));
                    return;
                }
                if (this._contribution < this._activateCostContri) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(57565));
                    return;
                }
                Alert.show(Language.getStringByParam(57575, 0), null, Alert.OK | Alert.CANCEL, null, onClickHandler);
            }
            return;
        }

        /* internal  */onGuildUpdateInfoHandler(arg1: SPlayerGuildInfo): void
        {
            if (arg1) 
            {
                this._resource = arg1.money;
                this._contribution = arg1.contribution;
                this._schoolLevel = Cache.instance.guild.getStructureLevel(EGuildStructureType.convert(EGuildStructureType._EGuildSchool));
            }
            return;
        }

        /* internal */ /* var */_skillItem: GuildSkillItem;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_levelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_upCostlTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_activateCostTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_upBtn: GButton;

        /* internal */ /* var */_activateBtn: GButton;

        /* internal */ /* var */_skill: TSkill;

        /* internal */ /* var */_upCostRes: int;

        /* internal */ /* var */_activateCostContri: int;

        /* internal */ /* var */_needSchoolLevel: int;

        /* internal */ /* var */_resource: int;

        /* internal */ /* var */_contribution: int;

        /* internal */ /* var */_schoolLevel: int;

        /* internal */ /* var */_enableSkillNum: int;

        /* internal */ /* var */_maxEnableNum: int=2;
    }
